<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php $this->load->view('admin/header.html')?>
<script type="text/javascript" src="<?php echo base_url()?>common/js/ck.js"></script>
<script type="text/javascript">
    function addbanner() {
        layer.open({
            type: 2,
            title: 'Banner添加',
            maxmin: true,
            shadeClose: true, //开启点击遮罩关闭层
            area: ['800px', '550px'],
            offset: ['100px', ''],
            content: '<?php echo site_url('admin/banner/addbanner')?>'
        });
    }
    function editbanner(bid) {
        url = "<?php echo site_url('admin/banner/editbanner/{bid}')?>";
        url = url.replace('{bid}', bid) + "?returnurl=" + window.location.href;
        layer.open({
            type: 2,
            title: 'Banner修改',
            maxmin: true,
            shadeClose: true, //开启点击遮罩关闭层
            area: ['800px', '550px'],
            offset: ['100px', ''],
            content: url
        });
    }
    function Success(data) {
        $.Success(data);
    }
    $(function () {
        $(".tableBasic form").each(function () {
            var itemsId = $(this).attr('id');
            var urles = {
                weight: {
                    required: true,
                    digits: true,
                    min: 0
                }
            };
            var banners = {
                weight: {
                    required: '权重必须填写',
                    digits: '请输入整数',
                    min: '权重最小值为0'
                }
            };
            $.my_validate("#" + itemsId, urles, banners);
            $("#" + itemsId).submit(function () {
                if ($.check_validate("#" + itemsId)) {
                    $(this).ajaxSubmit(function (data) {
                        var jsonData = $.parseJSON(data);
                        parent.Success(jsonData);
                    });
                }
                return false;
            });
        });
    })
     function Del(did)
    {
        var url = "/admin/banner/del_banner/" + did + "?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
        layer.confirm("确定删除", function () {
            $.post(url, null, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }
     function BatchDel() {
        layer.confirm("确定要删除？", function (index) {
            if ($("#checkboxVal").val().length <= 0) {
                layer.msg('未选择删除项，删除取消', { icon: 0 });
                return false;
            }
            var url = "/admin/banner/batchdel_banner?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
            $.post(url, { "items": $("#checkboxVal").val() }, function (data) {
                if (data.Statu == "ok") {
                    Success(data)
                    $("#allcheck").attr("checked", false)
                } else {
                    Success(data)
                }
            }, "json")
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }
</script>
<div id="dcMain">
    <!-- 当前位置 -->
    <div id="urHere">
        DouPHP 管理中心
        <b>></b>
        <strong>Banner管理</strong>
    </div>
    <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3>
            <a href="javascript:addbanner()" class="actionBtn">添加Banner</a>BANNER管理
        </h3>
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
            <tr>
                <th width="50" align="center"><label for="allcheck">选择</label> <input type="checkbox" id="allcheck" name="allcheck" class="allcheck" /></th>
                <th width="30" align="center">编号</th>
                <th align="left">图片</th>
                <th align="left">权重</th>
                <th align="center">操作</th>
            </tr>
            <?php foreach($bannerList as $bannerItem):?>
            <tr>
                <td align="center"><input type="checkbox" name="cklist" value="<?php echo $bannerItem->bid;?>" /></td>
                <td align="center"><?php echo $bannerItem->bid;?></td>

                <td><img src="<?php echo $bannerItem->imgurl;?>" style="height:40px;width:35px;" /></td>
                <td align="center">
                    <form id="ajax_form_<?php echo $bannerItem->bid?>" method="post" action="<?php echo site_url('admin/banner/set_banner_weight/'.$bannerItem->bid)?>?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>">
                        <input style="border:1px solid #949191;" type="text" name="weight" id="weight_<?php echo $bannerItem->bid?>" value="<?php echo $bannerItem->weight;?>" />&nbsp;<input type="submit" class="btn-mini" value="更新" />
                    </form>
                </td>
                <td align="center">
                    <a href="javascript:editbanner(<?php echo $bannerItem->bid?>)">编辑</a>|
                    <a href="javascript:Del(<?php echo $bannerItem->bid?>)">删除</a>
                </td>
            </tr>
            <?php endforeach; ?>

            <tr>
                <td colspan="10"><a href="javascript:BatchDel(14)">全部删除</a></td>
            </tr>
        </table>
        <input type="hidden" value="" id="checkboxVal" />
        <div class='page'>
            <?php echo $links?>
        </div>
    </div>
</div>

